import '../sass/common.scss';
import { initHeaderFooter } from './gopLib/initHeaderFooter';
import * as tools from './tools';

jQuery.support.cors = true;
$(function () {
  initHeaderFooter();
  init();

  const loginInfo = sessionStorage.getItem('loginInfo');
  if (!loginInfo) {
    let a = alert('请登录！！');
    location.href = './login.html';
  }

})

function init() {
  let id = tools.getArg('id');
  getVideoInfo(id);
}

function getVideoInfo(id) {
  $.ajax({
    url: tools.apiUrl + 'videoTutorial/getFrontEndVideoById',
    type: 'get',
    data: {
      id,
    },
    success: function (res) {
      if (res.code == 200) {
        renderVideoInfo(res.data);
      }
    }
  })
}

function renderVideoInfo(data) {

  $('.video_titile').html(`
    <p>视频培训：${data.directoryName} > <span>${data.title}</span></p>
  `)

  $('.video_content').append(`
      <video 
      id="video_p" 
      class="video-js vjs-big-play-centered" 
      controls 
      preload="auto" 
    >
      <source src="${data.url}" type="video/mp4"></source>
      <p class="vjs-no-js">
          To view this video please enable JavaScript, and consider upgrading to a web browser that
          <a href="http://videojs.com/html5-video-support/" target="_blank">
              supports HTML5 video
          </a>
      </p>
    </video>
  `);

  setTimeout(() => {
    tools.loadScript('http://vjs.zencdn.net/6.10/video.js', () => {
      let vid1 = videojs("video_p", {}, function () {
        // Player (this) is initialized and ready.
        $('#video_p').addClass('active__show')
      });
    })
  }, 250);

}